package com.ruoyi.dzzh.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dzzh.domain.DzzhPts;
import com.ruoyi.dzzh.service.IDzzhPtsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 灾害点Controller
 * 
 * @author cjt
 * @date 2023-04-07
 */
@RestController
@RequestMapping("/dzzh/pts")
public class DzzhPtsController extends BaseController
{
    @Autowired
    private IDzzhPtsService dzzhPtsService;

    /**
     * 查询灾害点列表
     */
    @PreAuthorize("@ss.hasPermi('dzzh:pts:list')")
    @GetMapping("/list")
    public TableDataInfo list(DzzhPts dzzhPts)
    {
        startPage();
        List<DzzhPts> list = dzzhPtsService.selectDzzhPtsList(dzzhPts);
        return getDataTable(list);
    }

    /**
     * 导出灾害点列表
     */
    @PreAuthorize("@ss.hasPermi('dzzh:pts:export')")
    @Log(title = "灾害点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzzhPts dzzhPts)
    {
        List<DzzhPts> list = dzzhPtsService.selectDzzhPtsList(dzzhPts);
        ExcelUtil<DzzhPts> util = new ExcelUtil<DzzhPts>(DzzhPts.class);
        util.exportExcel(response, list, "灾害点数据");
    }

    /**
     * 获取灾害点详细信息
     */
    @PreAuthorize("@ss.hasPermi('dzzh:pts:query')")
    @GetMapping(value = "/{ptsId}")
    public AjaxResult getInfo(@PathVariable("ptsId") Long ptsId)
    {
        return AjaxResult.success(dzzhPtsService.selectDzzhPtsByPtsId(ptsId));
    }

    /**
     * 新增灾害点
     */
    @PreAuthorize("@ss.hasPermi('dzzh:pts:add')")
    @Log(title = "灾害点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzzhPts dzzhPts)
    {
        return toAjax(dzzhPtsService.insertDzzhPts(dzzhPts));
    }

    /**
     * 修改灾害点
     */
    @PreAuthorize("@ss.hasPermi('dzzh:pts:edit')")
    @Log(title = "灾害点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzzhPts dzzhPts)
    {
        return toAjax(dzzhPtsService.updateDzzhPts(dzzhPts));
    }

    /**
     * 删除灾害点
     */
    @PreAuthorize("@ss.hasPermi('dzzh:pts:remove')")
    @Log(title = "灾害点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ptsIds}")
    public AjaxResult remove(@PathVariable Long[] ptsIds)
    {
        return toAjax(dzzhPtsService.deleteDzzhPtsByPtsIds(ptsIds));
    }
}
